package ch.bfh.swos.learnaid.repository;

import javax.inject.Inject;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import ch.bfh.swos.learnaid.model.Question;
import ch.bfh.swos.learnaid.repository.QuestionRepository;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/persistenceContext.xml")
public class QuestionRepositoryIT {

    @Inject
    private QuestionRepository questionRepository;
    
    @Test
    public void test() {
        // CREATE
        Question newQuestion = new Question();
        newQuestion.setText("Wie alt bist du?");
        questionRepository.save(newQuestion);
        
        //READ
        Question readQuestion = questionRepository.findOne(newQuestion.getId());
        org.junit.Assert.assertTrue(newQuestion.getText().equals(readQuestion.getText()));
        
        //UPDATE
        readQuestion.setText("Wie lautet deine Telefonnummer?");
        readQuestion = questionRepository.save(readQuestion);
        Question updatedQuestion = questionRepository.findOne(readQuestion.getId());
        org.junit.Assert.assertTrue(readQuestion.getText().equals(updatedQuestion.getText()));
        
        // DELETE
//        questionRepository.delete(updatedQuestion);
//        Question deletedQuestion = questionRepository.findOne(readQuestion.getId());
//        org.junit.Assert.assertNull(deletedQuestion);
    }

}
